<template>
	<div class="page page-association-newdetail has-headbar">
		<head-bar :title="this.$route.meta.title" :prevRoute="prevePage"  />
		<section class="head">
			<h1 class="title">{{title}}</h1>
			<div class="info"><span class="time">{{time}}</span></div>
		</section>
    <div class="banner" v-if="banner"><img :src="banner" alt=""></div>
		<div class="html-content" v-html="content"></div>
  </div>
</template>

<script>
import { API_ASSOCIATION_NEWS_DETAIL } from '@/service/association'
import { wxjsdkMixin } from '@/components/mixins'
import { getWechatLink } from '@/libs/utils'
export default {
  mixins: [wxjsdkMixin],
  name: 'association-newdetail',
  data () {
    return {
      title: '',
      author: '',
      time: '',
      content: '',
      banner: '',
      prevePage: { name: 'association-list' }
    }
  },
  beforeRouteEnter (to, from, next) {
    next(vm => {
      // console.log(from)
      if (from.name) {
        vm.prevePage = { name: from.name, query: from.query, params: from.params }
      }
    })
  },
  mounted () {
    this.wechatShowMenu()
    this.requestData().then(() => {
      let shareInfo = {
        title: this.title, // 分享标题
        desc: this.title,
        link: getWechatLink(window.location.hash), // 分享链接，该链接域名或路径必须与当前页面对应的公众号JS安全域名一致
        imgUrl: this.banner, // 分享图标
        success: function () {
          console.log('分享', getWechatLink(window.location.hash))
        }
      }
      this.wechatShare(shareInfo)
    })
  },
  methods: {
    requestData () {
      return API_ASSOCIATION_NEWS_DETAIL(this.$route.params.id).then((data) => {
        let info = data.info
        this.title = info.title
        this.time = info.createTime
        this.content = info.content
        this.banner = info.mainPicture
        document.title = data.info.title
      })
    }
  }
}
</script>

<style lang="less">
.page-association-newdetail{
  padding: 0 12px;
  @import "../../assets/styles/newsdetail.less";
}
</style>
